package com.bnyy.message.bean;

import com.bnyy.message.enums.MessageType;
import com.google.gson.annotations.SerializedName;

import org.xutils.db.annotation.Column;

import java.io.Serializable;

import static com.bnyy.message.bean.Message.ColumnName.*;

/**
 * Author : 关炳鹏
 * Description :
 * Date : 2022/6/30
 **/
public class Message implements Serializable {

    public interface ColumnName {
        String MSG_TYPE = "msg_type";
        String WEAR_ID = "wear_id";
        String IMEI = "imei";
        String SENDER_ID = "user_id";
        String GROUP_ID = "group_id";
        String RECIPIENT_ID = "recipient_id";
        String USER_NAME = "user_name";
        String USER_IMG = "user_img";
        String TAG = "tag";
        String TIME = "time";
        String MSG_ID = "msg_id";
        String SEND_STATUS = "send_status";
        String SOURCE_TYPE = "source_type";
        String SENDER_ROLE_ID = "role_id";
        String RECIPIENT_ROLE_ID = "to_role_id";
    }

    private MessageType messageType;

    @Column(name = MSG_TYPE)
    private int msg_type;

    @Column(name = WEAR_ID)
    private int wear_id;

    @Column(name = IMEI)
    private String imei;

    @Column(name = TAG)
    private long tag;

    @Column(name = TIME)
    private long time;

    /**
     * USERID_TIME_RANDOM
     */
    @Column(name = MSG_ID, isId = true, autoGen = false)
    @SerializedName("msg_id")
    private String msgId;

    @Column(name = SENDER_ID)
    @SerializedName("user_id")
    private int senderId;

    @Column(name = RECIPIENT_ID)
    @SerializedName("to_user_id")
    private int recipientId;

    @Column(name = GROUP_ID)
    @SerializedName("group_id")
    private int groupChatId;

    @Column(name = USER_NAME)
    private String username;

    @Column(name = USER_IMG)
    private String user_img;

    @Column(name = SOURCE_TYPE)
    private int source_type; // 消息来源 1 app 2 设备

    @Column(name = SENDER_ROLE_ID)
    @SerializedName("role_id")
    private int senderRoleId = 2;

    @Column(name = RECIPIENT_ROLE_ID)
    @SerializedName("to_role_id")
    private int  recipientRoleId = 2;

    private int location_auth;
    private String wear_name;

    private String relation;

    public Message() {
    }

    public Message(MessageType messageType) {
        setMessageType(messageType);
    }

    public MessageType getMessageType() {
        if (messageType == null) {
            messageType = MessageType.getMessageType(msg_type);
        }
        return messageType;
    }

    public void setMessageType(MessageType messageType) {
        this.messageType = messageType;
        this.msg_type = messageType.getType();
    }

    public int getMsg_type() {
        return msg_type;
    }

    public void setMsg_type(int msg_type) {
        this.msg_type = msg_type;
        this.messageType = MessageType.getMessageType(msg_type);
    }

    public void setMsgId(String msgId) {
        this.msgId = msgId;
    }

    public int getRecipientId() {
        return recipientId;
    }

    public void setRecipientId(int recipientId) {
        this.recipientId = recipientId;
    }

    public int getGroupChatId() {
        return groupChatId;
    }

    public void setGroupChatId(int groupChatId) {
        this.groupChatId = groupChatId;
    }

    public int getLocation_auth() {
        return location_auth;
    }

    public void setLocation_auth(int location_auth) {
        this.location_auth = location_auth;
    }

    public String getImei() {
        return imei;
    }

    public void setImei(String imei) {
        this.imei = imei;
    }

    public String getWear_name() {
        return wear_name;
    }

    public void setWear_name(String wear_name) {
        this.wear_name = wear_name;
    }

    public int getSource_type() {
        return source_type;
    }

    public void setSource_type(int source_type) {
        this.source_type = source_type;
    }

    private boolean showingSendFailureView; // 标记发送失败样式是否已经显示，避免重复刷新

    public boolean isShowingSendFailureView() {
        return showingSendFailureView;
    }

    public void setShowingSendFailureView(boolean showingSendFailureView) {
        this.showingSendFailureView = showingSendFailureView;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getUser_img() {
        return user_img;
    }

    public void setUser_img(String user_img) {
        this.user_img = user_img;
    }

    public String getMsgId() {
        return msgId;
    }

    public String getRelation() {
        return relation;
    }

    public void setRelation(String relation) {
        this.relation = relation;
    }

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public int getWear_id() {
        return wear_id;
    }

    public void setWear_id(int wear_id) {
        this.wear_id = wear_id;
    }

    public int getSenderId() {
        return senderId;
    }

    public void setSenderId(int senderId) {
        this.senderId = senderId;
    }

    public long getTag() {
        return tag;
    }

    public void setTag(long tag) {
        this.tag = tag;
        this.time = Math.abs(tag);
    }

    public int getSenderRoleId() {
        return senderRoleId;
    }

    public void setSenderRoleId(int senderRoleId) {
        this.senderRoleId = senderRoleId;
    }

    public int getRecipientRoleId() {
        return recipientRoleId;
    }

    public void setRecipientRoleId(int recipientRoleId) {
        this.recipientRoleId = recipientRoleId;
    }
}
